import 'dart:core';
import 'dart:math';
import 'package:event_bus/event_bus.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:unt/About.dart';
import 'package:unt/Intentpage.dart';
import 'package:unt/RowDemo.dart';
import 'package:unt/model_page.dart';

void main() {
  runApp(
    MaterialApp(home: TextHomePage()),
  );
}

class TextHomePage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return TextHomePageState();
  }
}

class TextHomePageState extends State<TextHomePage>
    with SingleTickerProviderStateMixin {
  late AnimationController _animationController;
  double size = 100;
  late Animation<double> animation;
  late Color color;
  late Animation _sizeAnimation;
  late Animation _colorAnimation;
  late Animation _opacityAnimation;
  late Animation _radiansAnimation;

  @override
  void initState() {
    super.initState();
    // 第一步创建 AnimationController
    setState(() {
      _animationController = AnimationController(
        vsync: this,
        duration: Duration(seconds: 2),
      );
    });
    // 第二步设置curve值
    animation =
        CurvedAnimation(parent: _animationController, curve: Curves.linear);
    _sizeAnimation = Tween(begin: 10.0, end: 200.0).animate(animation);
    _colorAnimation =
        ColorTween(begin: Colors.orange, end: Colors.purple).animate(animation);
    _opacityAnimation = Tween(begin: 0.0, end: 1.0).animate(animation);
    _radiansAnimation = Tween(begin: 0.0, end: 2 * pi).animate(animation);
    _animationController.addListener(() {
      setState(() {
        size = _sizeAnimation.value;
      });
    });
    _animationController.addStatusListener((status) {
      if (status == AnimationStatus.completed) {
        _animationController.reverse();
      } else if (status == AnimationStatus.dismissed) {
        _animationController.forward();
      }
    });
  }

  /**
   * 1。Animation: 抽象类
   *  *监听动画状态的改变
   *  *value
   *  *status
   *  2。AnimationController继承Animation
   *  *vsync 同步信号
   *  *forward（）： 向前执行动画
   *  *reverse（）： 反转执行动画
   *  3。CurvedAnimation：
   *   *作用 设置动画执行的速率（速度曲线）
   *   4。Tween：设置动画执行的value范围
   *    *begin： 开始值
   *    *end： 结束值
   */
  @override
  Widget build(BuildContext context) {
    // AnimationController(vsync: this);
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text("listview"),
        ),
        body: Center(
          child: Text("hellldllal"),
        ),
        floatingActionButton: FloatingActionButton(
          child: Icon(Icons.animation),
          onPressed: () {
            // Navigator.of(context).push(MaterialPageRoute(
            //     builder: (context) {
            //   return Modelpage();
            // },
            //   fullscreenDialog: true
            // ));
            Navigator.of(context).push(
                // 这里不在采用MaterialPageRoute而是采用PageRouteBuilder
                PageRouteBuilder(
                    //  下面这行代码设置跳转延时
                    transitionDuration: Duration(seconds: 4),
                    pageBuilder: (context, animation1, animation2) {
                      return FadeTransition(
                        //设置透明度，这样页面出来的时候就是淡入淡出的效果
                        opacity: animation1,
                        child: Modelpage(),
                      );
                    }));
          },
        ),
      ),
    );
  }

  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
    _animationController.dispose();
  }
}
